﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WiMoGF.Config
{
    class Project
    {
public const string PROJECT_WINMO =  @"Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""$projectnamespace$"", ""$projectnamespace$.csproj"", ""{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}""
EndProject
";

public const string PROJECT_SILVERLIGHT = @"Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""$projectnamespace$.Silverlight"", ""$projectnamespace$.Silverlight.csproj"", ""{C9307050-0A8A-4BA4-8288-BBCF3408A57B}""
EndProject
";

public const string PROJECT_ZUNEHD = @"Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""$projectnamespace$.ZuneHD"", ""$projectnamespace$.ZuneHD.csproj"", ""{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}""
EndProject
";

public const string PROJECT_WEB = @"Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""$projectnamespace$.Web"", ""SilverlightHost\$projectnamespace$.Web.csproj"", ""{0AD4E767-4455-4CBB-A301-13A4C9F417D8}""
EndProject
";

        public const string SETTINGS_WEB = @"		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Debug|Zune.ActiveCfg = Debug|Any CPU
		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{0AD4E767-4455-4CBB-A301-13A4C9F417D8}.Release|Zune.ActiveCfg = Release|Any CPU
";
         public const string SETTINGS_UNKNOWN = @"    {E8C8EFA7-8464-419B-8385-A967FF29D5A9}.Debug|Any CPU.ActiveCfg = Debug|Zune
		{E8C8EFA7-8464-419B-8385-A967FF29D5A9}.Debug|Mixed Platforms.ActiveCfg = Debug|Zune
		{E8C8EFA7-8464-419B-8385-A967FF29D5A9}.Debug|Zune.ActiveCfg = Debug|Zune
		{E8C8EFA7-8464-419B-8385-A967FF29D5A9}.Release|Any CPU.ActiveCfg = Release|Zune
		{E8C8EFA7-8464-419B-8385-A967FF29D5A9}.Release|Mixed Platforms.ActiveCfg = Release|Zune
		{E8C8EFA7-8464-419B-8385-A967FF29D5A9}.Release|Zune.ActiveCfg = Release|Zune
";

         public const string SETTINGS_ZUNE = @"    {64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Debug|Any CPU.ActiveCfg = Debug|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Debug|Any CPU.Build.0 = Debug|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Debug|Mixed Platforms.ActiveCfg = Debug|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Debug|Mixed Platforms.Build.0 = Debug|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Debug|Mixed Platforms.Deploy.0 = Debug|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Debug|Zune.ActiveCfg = Debug|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Release|Any CPU.ActiveCfg = Release|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Release|Mixed Platforms.ActiveCfg = Release|Zune
		{64BBEF29-1C15-4EA5-9E8F-58FC3FC7E207}.Release|Zune.ActiveCfg = Release|Zune
";


        public const string SETTINGS_SILVERLIGHT = @"{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Debug|Zune.ActiveCfg = Debug|Any CPU
		{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{C9307050-0A8A-4BA4-8288-BBCF3408A57B}.Release|Zune.ActiveCfg = Release|Any CPU
";

        public const string SETTINGS_WINMO = @"{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Debug|Zune.ActiveCfg = Debug|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
		{BC5552E8-8A35-4CBD-A23F-B050DE09A05D}.Release|Zune.ActiveCfg = Release|Any CPU
";


        public static void CreateProject(string directory, string projectName, bool? windowsMobile, bool? silverlight, bool? zuneHd)
        {         
            var projectItem = new ProjectItem("GameOne.Silverlight.csproj", false, projectName);
            projectItem.RenameFile("GameOne", projectName);
            var slProjectId = projectItem.ProjectId;
            projectItem.Write(directory);

            projectItem = new ProjectItem("App.xaml", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("App.xaml.cs", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Game.cs", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Properties","AppManifest.xml", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Properties", "AssemblyInfo.cs", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("GameOne.ZuneHD.csproj", false, projectName);
            var zuneProjectId = projectItem.ProjectId;
            projectItem.RenameFile("GameOne", projectName);            
            projectItem.Write(directory);

            projectItem = new ProjectItem("Program.ZuneHD.cs", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("GameThumbnail.png", true, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Content","Content.contentproj", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Content", "Default.spritefont", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("GameOne.csproj", false, projectName);
            var wimoProjectId = projectItem.ProjectId;
            projectItem.RenameFile("GameOne", projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Program.cs", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Properties","Resources.Designer.cs", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("Properties", "Resources.resx.File", true, projectName);
            projectItem.RenameFile("Resources.resx.File", "Resources.resx");
            projectItem.Write(directory);

            projectItem = new ProjectItem("SilverlightHost","GameOne.Web.csproj", false, projectName);
            projectItem.RenameFile("GameOne", projectName);
            projectItem.SetProjectReferenceId(ProjectItem.SL_PROJECT_ID, slProjectId.ToString());
            var webProjectId = projectItem.ProjectId;
            projectItem.Write(directory);

            projectItem = new ProjectItem("SilverlightHost", "GameOneTestPage.html", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("SilverlightHost", "Silverlight.js", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("SilverlightHost", "Web.config", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem(@"SilverlightHost\Properties", "AssemblyInfo.cs", false, projectName);
            projectItem.Write(directory);

            projectItem = new ProjectItem("GameOne.sln", false, projectName);
            var projects = new StringBuilder();
            var buildSettings = new StringBuilder();
            if(windowsMobile.Value){
                projects.Append(PROJECT_WINMO);
                buildSettings.Append(SETTINGS_WINMO);
            }

            if (zuneHd.Value)
            {
                projects.Append(PROJECT_ZUNEHD);
                buildSettings.Append(SETTINGS_ZUNE);
            }

            if(silverlight.Value)
            {
                projects.Append(PROJECT_SILVERLIGHT);
                projects.Append(PROJECT_WEB);
                buildSettings.Append(SETTINGS_WEB);
                buildSettings.Append(SETTINGS_SILVERLIGHT);
            }

            projectItem.ReplaceTags("$projects$", projects.ToString());
            projectItem.ReplaceTags("$buildsettings$", buildSettings.ToString());

            projectItem.RenameFile("GameOne", projectName);
            projectItem.SetProjectReferenceId(ProjectItem.ZUNE_PROJECT_ID, zuneProjectId.ToString());
            projectItem.SetProjectReferenceId(ProjectItem.SL_PROJECT_ID, slProjectId.ToString());
            projectItem.SetProjectReferenceId(ProjectItem.WIMO_PROJECT_ID, wimoProjectId.ToString());
            projectItem.SetProjectReferenceId(ProjectItem.WEB_PROJECT_ID, webProjectId.ToString());
            projectItem.Write(directory);
        }
    }
}
